package com.woniuxy.springbootmybatis.service.impl;

import com.woniuxy.springbootmybatis.entity.User;
import com.woniuxy.springbootmybatis.mapper.UserMapper;
import com.woniuxy.springbootmybatis.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author linke
 * @version 1.0
 * @className: UserServiceImpl
 * @description: TODO 类描述
 * @date 2021/11/16 20:12
 */
@Transactional(readOnly = true)
@Service
public class UserServiceImpl implements IUserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> all() {
        return userMapper.all();
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int add(User user) {
//        System.out.println(1/0);//测试异常事务是否提交
        return userMapper.add(user);
    }
}
